import { defineStore } from 'pinia'
import { ref, type Ref } from 'vue'
interface IUserInfo {
  roleid: number
  routes: string[]
  uname: string
  userid: string
  avatar: string
}
const origin: IUserInfo = {
  roleid: 0,
  routes: [],
  uname: '',
  userid: '',
  avatar: '',
}
export const useUserStore = defineStore(
  'user',
  () => {
    const token: Ref<string> = ref('')
    const userInfo: Ref<IUserInfo> = ref({ ...origin })
    const clearUserInfo = () => {
      token.value = ''
      userInfo.value = { ...origin }
    }
    return { token, userInfo, clearUserInfo }
  },
  {
    persist: {
      storage: localStorage,
      key: 'user',
    },
  },
)
